<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form v-if="tabsKeys != 2" size="small" :model="pageData" layout="inline">
            <a-form-item label="单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.g"
              />
            </a-form-item>
            <CorporateSectorCascader
              :configCascader="configCascader3"
              @changeCascader="changeCascader3"
            />
            <a-form-item label="仓库">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.b"
                allow-clear
              >
                <a-option v-for="item in fhWhList3" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>

            <a-form-item label="物料编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.d"
              />
            </a-form-item>
            <a-form-item label="物料名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.e"
              />
            </a-form-item>
            <a-form-item label="日期">
              <a-range-picker
                popup-container="html"
                :style="{ width: '240px' }"
                class="bacClass"
                @clear="onClear"
                allow-clear
                v-model="pageData.dropDownTime"
              />
            </a-form-item>
          </a-form>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div style="text-align: end">
        <Toolbar
          :items="toolbarList"
          @xzgzckd="adddbs(3)"
          @addCk="adddbs(1)"
          @add-db="adddbs(2)"
          @del="delSles"
          @audit="audits"
          @oders="redersOut"
          @returnList="returnList"
          @select="selectHandler"
          @addScrap="adddbs(4)"
        >
        </Toolbar>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs :lazy-load="true" :justify="true" default-active-key="1" @change="tabsChanges">
        <a-tab-pane title="待处理" key="1">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList"
            :columnDefs="tc"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet2.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize2"
            @page-size-change="change2"
            style="justify-content: center"
            :page-size="fySelet2.size"
            :current="fySelet2.page"
          />
        </a-tab-pane>
        <!-- <a-tab-pane title="待归还单据" key="2">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady2"
            style="height:94%" :defaultColDef="defaultColDef2" class='ag-theme-alpine' :rowData="tableDataList2"
            :columnDefs="tc2" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="fySelet.total" show-total show-jumper show-page-size
            @change="PageSize" @page-size-change="change" style="justify-content: center" :page-size="fySelet.size"
            :current="fySelet.page" />
        </a-tab-pane> -->
        <a-tab-pane title="出入记录" key="3">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady3"
            @columnResized="onColumnResized3"
            @columnMoved="onColumnMoved3"
            @columnVisible="onColumnVisible3"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef2"
            class="ag-theme-alpine"
            :rowData="tableDataList3"
            :columnDefs="tc3"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet3.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize3"
            @page-size-change="change3"
            style="justify-content: center"
            :page-size="fySelet3.size"
            :current="fySelet3.page"
          />
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-modal
      v-model:visible="cgOut.visible"
      :on-before-ok="cgHandleOk"
      @cancel="cadelvs"
      fullscreen
      :mask-closable="false"
    >
      <template #title>
        {{ cgOut.title }}
      </template>
      <a-table :columns="cgColumns" :data="cgData" :pagination="false" :bordered="{ cell: true }">
      </a-table>
    </a-modal>
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      height="100%"
      :visible="dbPageDate.showAdd"
      @ok="sideOk"
      placement="bottom"
      @cancel="sideNo"
    >
      <template #title>
        {{ dbPageDate.titles }}
      </template>
      <div style="min-width: 1500px; height: 100%">
        <el-scrollbar>
          <a-form
            ref="formRef"
            layout="inline"
            :model="searchData"
            size="mini"
            v-if="
              dbPageDate.titles == '新建出库单' ||
              dbPageDate.titles == '新增固资出库单' ||
              dbPageDate.titles == '新增报废'
            "
          >
            <CorporateSectorCascader
              :configCascader="configCascader"
              @changeCascader="changeCascader"
            />
            <a-form-item
              label="仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="fhWh"
              v-if="dbPageDate.titles == '新建出库单' || dbPageDate.titles == '新增报废'"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.fhWh"
                allow-clear
              >
                <a-option v-for="item in fhWhList" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item
              label="出库类型"
              field="outStockType"
              :rules="[{ required: true, message: '出库类型必填' }]"
            >
              <a-select
                :disabled="dbPageDate.titles == '新增固资出库单'"
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.outStockType"
                v-if="dbPageDate.titles !== '新增报废'"
                @focus="cxOutStockType"
                allow-clear
              >
                <a-option v-for="item in outStockTypeList" :value="item['typeName']">
                  {{ item['typeName'] }}
                </a-option>
              </a-select>
              <a-select
                :disabled="dbPageDate.titles == '新增报废'"
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.outStockType"
                v-if="dbPageDate.titles == '新增报废'"
                @focus="cxOutStockType"
                allow-clear
              >
                <a-option value="报废出库"> 报废出库 </a-option>
              </a-select>
            </a-form-item>
            <a-form-item
              label-col-flex="80px"
              label="机台编号"
              v-if="dbPageDate.titles !== '新增报废'"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.machineCode"
                allow-clear
                @click="machineNameCodeCx('')"
                @search="machineNameCodeCx"
                @change="machineNameCodeChange"
                :filter-option="false"
                :disabled="!searchData.fhFirmId"
                allow-create
                allow-search
              >
                <a-option
                  v-for="item in machineNameCode"
                  :value="item.machineCode + '-' + item.machineName"
                >
                  {{ item.machineCode + ' —— ' + item.machineName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item
              label-col-flex="80px"
              label="机台名称"
              v-if="dbPageDate.titles !== '新增报废'"
            >
              <a-input
                class="bacClass"
                v-model="searchData.machineName"
                :style="{ width: '10rem' }"
                disabled
              ></a-input>
            </a-form-item>
          </a-form>
          <a-form
            ref="formRef"
            layout="inline"
            :model="searchData"
            size="mini"
            v-if="dbPageDate.titles == '新建调拨单'"
          >
            <CorporateSectorCascader
              :configCascader="configCascader"
              @changeCascader="changeCascader"
            />
            <a-form-item
              label="发货仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="fhWh"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.fhWh"
                allow-clear
              >
                <a-option v-for="item in fhWhList" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <CorporateSectorCascader1
              :configCascader="configCascader2"
              @changeCascader="changeCascader2"
            />
            <a-form-item
              label="收货仓库类型"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="shWhType"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                allow-search
                v-model="searchData.shWhType"
                allow-clear
                @change="whTypeChanges"
              >
                <a-option>五金仓</a-option>
                <a-option>制具仓</a-option>
              </a-select>
            </a-form-item>
            <a-form-item
              label="收货仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="shWh"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.shWh"
                allow-clear
              >
                <a-option v-for="item in shWhList" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
          </a-form>

          <a-space style="margin-bottom: 10px">
            <a-button type="primary" @click="addLine" size="mini">新增</a-button>
            <a-button type="primary" @click="delLine" size="mini">删除</a-button>
          </a-space>
          <!-- <a-table v-if="dbPageDate.titles == '新增固资出库单'" stripe :bordered="true" :columns="dc5" size="mini"
            :data="wlListArray" :row-selection="{ showCheckedAll: true, width: 50 }" rowKey="numberId"
            v-model:selected-keys="selectedRowKeysWl">
          </a-table> -->
          <div style="width: 98%; height: 100%; overflow: auto">
            <AgGridVuesCopys
              v-if="dbPageDate.titles == '新增固资出库单'"
              :rowHeight="33"
              :headerHeight="33"
              :suppressCopyRowsToClipboard="true"
              :suppressDragLeaveHidesColumns="true"
              rowSelection="multiple"
              @grid-ready="gridReady6"
              style="height: 90%; width: 100%"
              :defaultColDef="defaultColDef2"
              class="ag-theme-alpine"
              :rowData="wlListArray"
              :columnDefs="dc5"
              :localeText="localeText1"
            ></AgGridVuesCopys>
            <AgGridVuesCopys
              v-else
              :rowHeight="33"
              :headerHeight="33"
              :suppressCopyRowsToClipboard="true"
              :suppressDragLeaveHidesColumns="true"
              rowSelection="multiple"
              @grid-ready="gridReady6"
              style="height: 90%; width: 100%"
              :defaultColDef="defaultColDef2"
              class="ag-theme-alpine"
              :rowData="wlListArray"
              :columnDefs="tableColumnsWl"
              :localeText="localeText1"
            ></AgGridVuesCopys>
          </div>
          <!-- <a-table v-else stripe :bordered="true" :columns="tableColumnsWl" size="mini" :data="wlListArray"
            :row-selection="{ showCheckedAll: true, width: 50 }" rowKey="typeLesIds"
            v-model:selected-keys="selectedRowKeysWl">
            <template #totalNum="{ record }">
              <div style="width: 100%">
                <a-input-number v-model="record.totalNum" class="input-demo bacClass" :min="0"
                  :max="record.totalNum2 - record.useNum" :precision="2" />
              </div>
            </template>
          </a-table> -->
        </el-scrollbar>
      </div>
    </a-drawer>
    <a-modal
      v-model:visible="cgOut.visible2"
      :on-before-ok="cgHandleOk2"
      @cancel="cadelvs2"
      fullscreen
      :mask-closable="false"
    >
      <template #title> 调拨出库修改 </template>
      <!-- <a-table :columns="cgColumns2" :data="cgData2" :pagination="false" :bordered="{ cell: true }">
        <template #totalNum="{ record }">
          <a-input-number class="bacClass" v-model="record.totalNum" :max="record.totalNum2 - record.useNum"
            :min="0"></a-input-number>
        </template>
      </a-table> -->
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        :suppressDragLeaveHidesColumns="true"
        rowSelection="multiple"
        @grid-ready="gridReady2_1"
        style="height: 600px; width: 100%"
        :defaultColDef="defaultColDef2"
        class="ag-theme-alpine"
        :rowData="cgData2"
        :columnDefs="cgColumns2"
        :localeText="localeText1"
      ></AgGridVuesCopys>
    </a-modal>
    <a-modal
      fullscreen
      v-model:visible="visibleYl"
      :on-before-ok="handleOks"
      @cancel="handleCancels"
      :mask-closable="false"
    >
      <template #title>制具仓库存</template>
      <div class="cgisDatas">
        <div>
          <span>物料编号:</span
          ><a-input class="bacClass" v-model="isLyCodeds" :style="{ width: '150px' }" allow-clear />
        </div>
        <div>
          <span>物料名称:</span
          ><a-input class="bacClass" v-model="isLyNameds" :style="{ width: '150px' }" allow-clear />
        </div>
        <a-button type="primary" size="mini" @click="cxCgsLists">查询</a-button>
      </div>
      <!-- <a-table :style="{
        height: '500px',
        marginTop: '10px',
      }" :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }" rowKey="typeLesIds"
        v-model:selected-keys="selectedRowKeys2" stripe :bordered="true" :scrollbar="true" sticky-header
        :pagination="false" :columns="cgColumns5" :data="wlListXqs">
      </a-table> -->
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        :suppressDragLeaveHidesColumns="true"
        rowSelection="multiple"
        @grid-ready="gridReady4"
        style="height: 600px"
        :defaultColDef="defaultColDef2"
        class="ag-theme-alpine"
        :rowData="wlListXqs"
        :columnDefs="cgColumns5"
        :localeText="localeText1"
      ></AgGridVuesCopys>
      <paginationCopys
        :page-size-options="pagingList1"
        :total="fySelet4.total"
        show-total
        show-jumper
        show-page-size
        @change="PageSize4"
        @page-size-change="change4"
        style="justify-content: center"
        :page-size="fySelet4.size"
        :current="fySelet4.page"
      />
    </a-modal>
    <a-modal
      fullscreen
      v-model:visible="visibleYl1"
      :on-before-ok="handleOks5"
      @cancel="handleCancels5"
      :mask-closable="false"
    >
      <template #title>固定资产资料</template>
      <div class="cgisDatas">
        <div>
          <span>物料大类:</span
          ><a-input
            class="bacClass"
            v-model="isLists.majorCategory"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <div>
          <span>物料中类:</span
          ><a-input
            class="bacClass"
            v-model="isLists.middleCategory"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <div>
          <span>物料小类:</span
          ><a-input
            class="bacClass"
            v-model="isLists.subCategory"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <div>
          <span>物料名称:</span
          ><a-input
            class="bacClass"
            v-model="isLists.materialName"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <div>
          <span>规格:</span
          ><a-input
            class="bacClass"
            v-model="isLists.specification"
            :style="{ width: '150px' }"
            allow-clear
          />
        </div>
        <a-button type="primary" size="mini" @click="cxCgsLists1">查询</a-button>
      </div>
      <!-- <a-table :style="{
        height: '500px',
        marginTop: '10px',
      }" :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }" rowKey="numberId"
        v-model:selected-keys="selectedRowKeys5" stripe :bordered="true" :scrollbar="true" sticky-header
        :pagination="false" :columns="dc5" :data="wlListXqs1">
      </a-table> -->
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        :suppressDragLeaveHidesColumns="true"
        rowSelection="multiple"
        @grid-ready="gridReady5"
        style="height: 600px"
        :defaultColDef="defaultColDef2"
        class="ag-theme-alpine"
        :rowData="wlListXqs1"
        :columnDefs="dc5"
        :localeText="localeText1"
      ></AgGridVuesCopys>

      <paginationCopys
        :page-size-options="pagingList1"
        :total="fySelet5.total"
        show-total
        show-jumper
        show-page-size
        @change="PageSize5"
        @page-size-change="change5"
        style="justify-content: center"
        :page-size="fySelet5.size"
        :current="fySelet5.page"
      />
    </a-modal>

    <!-- 归还弹窗 -->
    <a-modal fullscreen v-model:visible="visible3">
      <template #title>单据归还</template>
      <!-- <a-table :style="{ height: '500px', marginTop: '10px' }" rowKey="id" v-model:selected-keys="selectedRowKeys3" stripe
        :bordered="true" :scrollbar="true" sticky-header :pagination="false" :columns="tc4" :data="tableDataList4">
        <template #newNum2="{ record }">
          <a-input-number v-model="record.newNum2" class="bacClass" :min="0" @change="Num(1, record)" :precision="2" />
        </template>
        <template #degraded="{ record }">
          <a-select popup-container="html" @click="gradeChange2()" class="bacClass" v-model="record.degraded" allow-clear>
            <a-option v-for="item in gradrList2">{{ item }}</a-option>
          </a-select>
        </template>
        <template #degraNum="{ record }">
          <a-input-number v-model="record.degraNum" class="bacClass" :min="0" @change="Num(2, record)" :precision="2" />
        </template>
        <template #scrapNum="{ record }">
          <a-input-number v-model="record.scrapNum" class="bacClass" :min="0" :precision="2"
            :disabled="record.infoType == 3" />
        </template>
      </a-table> -->
      <div style="width: 100%; height: 100%; overflow: auto">
        <encapsulation-agrid
          ref="gridOptionRef2"
          :configaggrid="configaggrid"
        ></encapsulation-agrid>
      </div>
      <template #footer>
        <el-button @click="visible3 = false">取消</el-button>
        <el-button type="primary" @click="handleOk">确认</el-button>
      </template>
    </a-modal>
    <!-- 详情 -->
    <a-modal fullscreen v-model:visible="visibleA">
      <template #title>详情</template>
      <!-- <a-table :style="{ height: '500px', marginTop: '10px' }" rowKey="id" v-model:selected-keys="selectedRowKeys3" stripe
        :bordered="true" :scrollbar="true" sticky-header :pagination="false" :columns="tcA" :data="tableDataListA">
      </a-table> -->
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        :suppressDragLeaveHidesColumns="true"
        rowSelection="multiple"
        @grid-ready="gridReadyA"
        style="height: 600px; margin-top: 10px"
        :defaultColDef="defaultColDef2"
        class="ag-theme-alpine"
        :rowData="tableDataListA"
        :columnDefs="tcA"
        :localeText="localeText1"
      ></AgGridVuesCopys>
      <template #footer>
        <el-button @click="visibleA = false">取消</el-button>
      </template>
    </a-modal>

    <!-- 批量归还 -->
    <a-modal
      fullscreen
      v-model:visible="visible4"
      :on-before-ok="handleOk1"
      @cancel="visible4 = false"
      ok-text="确认"
      cancelText="取消"
    >
      <template #title>批量归还</template>
      <div style="width: 100%; height: 100%; overflow-x: auto">
        <encapsulation-agrid
          ref="gridOptionRef3"
          :configaggrid="configaggrid3"
        ></encapsulation-agrid>
      </div>
    </a-modal>
  </pageTabelLayout>
</template>
<script setup lang="ts">
  import { ElMessage, ElMessageBox } from 'element-plus'
  import { ref } from 'vue'
  import { post, get } from '@/api/http'
  import { localeText } from '@/api/aggridZw'
  
  import Toolbar from '@/components/Toolbar.vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  import dayjs from 'dayjs'
  import CorporateSectorCascader1 from '@/components/corporateSectorCascader1/index.vue'
  import WHService from '@/service/wh'
  import usePermission from '@/store/modules/permission'
  import { pagingList } from '@/api/paging'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState03 } from '@/hooks/useGridState'
  import setTableTotalRow from '@/utils/setTableTotalRow.ts'
  const pagingList1: any = ref(pagingList)
  const permissionStore = usePermission()
  const gridOptionRef2: any = ref(null)
  const tableColumns2: any = [
    {
      headerName: '唯一编号',
      field: 'numberId',
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
    },
    {
      headerName: '物料名称',
      field: 'materialName',
    },
    {
      headerName: '等级',
      field: 'grade',
    },
    {
      headerName: '原数量',
      field: 'oldNum',
    },
    {
      headerName: '已归还数量化',
      field: 'newNum',
    },
    {
      headerName: '单位',
      field: 'unit',
    },

    {
      headerName: '归还数量',
      key: 'newNum2',
      field: 'newNum2',
      slotName: 'newNum2',
      cellRenderer: {
        template: `
        <a-input-number v-model="record.newNum2" class="bacClass" :min="0" @change="callNum(1, record)" :precision="2" />
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callNum = (a: any, b: any) => {
            Num(a, b)
          }
          return {
            record,
            callNum,
          }
        },
      },
    },
    {
      headerName: '降等等级',
      field: 'degraded',
      slotName: 'degraded',
      cellRenderer: {
        template: `
        <a-select popup-container="html" @click="callGradeChange2()" class="bacClass" v-model="record.grade" allow-clear>
            <a-option v-for="item in gradrList2">{{ item }}</a-option>
          </a-select>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callGradeChange2 = () => {
            gradeChange2()
          }
          return {
            record,
            callGradeChange2,
            gradrList2,
          }
        },
      },
    },
    {
      headerName: '降等数量',
      field: 'degraNum',
      slotName: 'degraNum',
      cellRenderer: {
        template: `
        <a-input-number v-model="record.degraNum" class="bacClass" :min="0" @change="callNum(2, record)" :precision="2" />
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callNum = (a: any, b: any) => {
            Num(a, b)
          }
          return {
            record,
            callNum,
          }
        },
      },
    },
    {
      headerName: '报废数量',
      field: 'scrapNum',
      slotName: 'scrapNum',
      cellRenderer: {
        template: `
        <a-input-number v-model="record.scrapNum" class="bacClass" :min="0" :precision="2"
            :disabled="record.infoType == 3" />
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          return {
            record,
          }
        },
      },
      // fixed: 'right',
    },
  ]
  let configaggrid = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns2,
    fileName: 'AccessRecordReturn',
  })
  const gridOptionRef3: any = ref(null)
  const tableColumns3: any = [
    {
      headerName: '单号',
      field: 'orderNo',
    },
    {
      // 0手动创建出库 1针盘借出出库 2调拨出库
      headerName: '类型',
      field: 'infoType',
      slotName: 'infoType',
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
    },
    {
      headerName: '公司',
      field: 'companyName',
    },
    {
      headerName: '仓库类别',
      field: 'warehouseTypeName',
    },
    {
      headerName: '仓库',
      field: 'warehouseName',
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
    },
    {
      headerName: '物料名称',
      field: 'materialName',
    },
    {
      headerName: '规格',
      field: 'specification',
    },
    {
      headerName: '单位',
      field: 'unit',
    },
    {
      headerName: '等级',
      field: 'grade',
      pinned: 'right',
      width: 110,
    },

    {
      headerName: '原数量',
      field: 'totalNum',
      pinned: 'right',
      width: 110,
    },
    {
      headerName: '已归还数量',
      field: 'returnNumed',
      pinned: 'right',
      width: 120,
    },
    {
      headerName: '待归还数量',
      field: 'awaitNumed',
      pinned: 'right',
      slotName: 'awaitNumed',
      width: 120,
    },

    {
      headerName: '归还类型',
      field: 'inStockType',
      slotName: 'inStockType',
      pinned: 'right',
      width: 110,
    },
    {
      headerName: '归还数量',
      field: 'totalNumIng',
      slotName: 'totalNumIng',
      pinned: 'right',
      width: 110,
      cellRenderer: {
        template: `
        <a-input-number
            v-model="record.totalNumIng"
            class="bacClass"
            :min="0"
            @change="callNum1()"
            :precision="4"
          />
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callNum1 = () => {
            Num1()
          }
          return {
            record,
            callNum1,
          }
        },
      },
    },
    {
      headerName: '降后等级',
      field: 'degraded',
      slotName: 'degraded',
      pinned: 'right',
      width: 110,
      cellRenderer: {
        template: `
        <a-select
            popup-container="html"
            @click="callGradeChange3(record)"
            class="bacClass"
            v-model="record.degraded"
            allow-clear
          >
            <a-option v-for="item in gradrList3">{{ item }}</a-option>
          </a-select>
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callGradeChange3 = (a: any) => {
            gradeChange3(a)
          }
          return {
            record,
            callGradeChange3,
            gradrList3,
          }
        },
      },
    },
    {
      headerName: '降等数量',
      field: 'degraNum',
      slotName: 'degraNum',
      pinned: 'right',
      width: 110,
      cellRenderer: {
        template: `
        <a-input-number
            v-model="record.degraNum"
            class="bacClass"
            :min="0"
            @click="callDegraNum1(record)"
            @change="callNum1()"
            :precision="4"
          />
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callDegraNum1 = (a: any) => {
            degraNum1(a)
          }
          const callNum1 = (a: any) => {
            Num1()
          }
          return {
            record,
            callDegraNum1,
            callNum1,
          }
        },
      },
    },
    {
      headerName: '报废数量',
      field: 'scrapNum',
      slotName: 'scrapNum',
      pinned: 'right',
      width: 110,
      cellRenderer: {
        template: `
        <a-input-number
            v-model="record.scrapNum"
            class="bacClass"
            :min="0"
            @change="callNum1()"
            :precision="4"
          />
        `,
        setup(props: any) {
          const record = ref(props.params.data)
          const callNum1 = (a: any) => {
            Num1()
          }
          return {
            record,
            callNum1,
          }
        },
      },
    },
    {
      headerName: '操作',
      field: 'del',
      slotName: 'del',
      pinned: 'right',
      width: 110,
    },
  ]
  let configaggrid3 = ref({
    url: '', //接口路径
    queryData: {
      //接口参数
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns3,
    fileName: 'AccessRecordSomeReturn',
  })
  const toolbarList: any = ref([
    `${permissionStore.hasPermisson('zjcck.cx') ? '查询' : ''}`,
    '新增固资出库单',
    `${permissionStore.hasPermisson('zjcck.xzckd') ? '新建出库单' : ''}`,
    `${permissionStore.hasPermisson('zjcck.xzckd') ? '新建调拨单' : ''}`,
    `${permissionStore.hasPermisson('zjcck.xzbf') ? '新增报废' : ''}`,
    `${permissionStore.hasPermisson('zjcck.sh') ? '审核' : ''}`,
    `${permissionStore.hasPermisson('zjcck.sc') ? '删除' : ''}`,
  ])

  const fySelet: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize = (val: any) => {
    fySelet.page = val
    cxCgsList()
  }

  const change = (val: any) => {
    fySelet.size = val
    cxCgsList()
  }

  const fySelet2: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })
  const fySelet3: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })
  const PageSize2 = (val: any) => {
    fySelet2.page = val
    cxYcList()
  }
  const PageSize3 = (val: any) => {
    fySelet3.page = val
    ghList()
  }
  const change2 = (val: any) => {
    fySelet2.size = val
    cxYcList()
  }
  const change3 = (val: any) => {
    fySelet3.size = val
    ghList()
  }

  const headerShow = ref(true)

  const pageData: any = reactive({
    a: null,
    b: null,
    c: null,
    d: null,
    e: null,
    f: null,
    g: null,
    dropDownTime: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
  })

  const tableDataList = ref([])
  const tableDataList2 = ref([])
  const tableDataList3 = ref([])
  const tableDataList4 = ref([])
  const tableDataListA = ref([])

  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }

  const gridOption2 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
  }

  const gridOption2_1 = ref()
  const gridReady2_1 = (params: any) => {
    gridOption2_1.value = params.api
  }

  const gridOption3 = ref()
  const colState3 = ref()
  const gridReady3 = (params: any) => {
    gridOption3.value = params.api
    colState3.value = params.columnApi
  }

  const gridOption4 = ref()
  const colState4 = ref()
  const gridReady4 = (params: any) => {
    gridOption4.value = params.api
    colState4.value = params.columnApi
  }

  const gridOption5 = ref()
  const colState5 = ref()
  const gridReady5 = (params: any) => {
    gridOption5.value = params.api
    colState5.value = params.columnApi
  }

  const gridOption6 = ref()
  const colState6 = ref()
  const gridReady6 = (params: any) => {
    gridOption6.value = params.api
    colState6.value = params.columnApi
  }

  const gridOptionA = ref()
  const gridReadyA = (params: any) => {
    gridOptionA.value = params.api
  }

  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const defaultColDef2 = {
    sortable: true,
    resizable: true,
    filter: true,
  }
  let oneDayTime: any = ref([dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')])
  const localeText1: any = ref(localeText)

  const tc = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      // 0手动创建出库 1针盘借出出库 2调拨出库
      headerName: '类型',
      field: 'infoType',
      width: 150,
      cellRenderer: {
        template: `<span>{{states==1?'针盘借出出库':states==2?'调拨出库':'手动创建出库'}}</span>`,
        setup(props: any) {
          return {
            states: props.params.data.infoType,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '1'
            ? '针盘借出出库'
            : params.value == '2'
            ? '调拨出库'
            : '手动创建出库'
        },
      },
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      width: 150,
    },
    {
      headerName: '公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '收货仓库类型',
      field: 'inWarehouseTypeName',
      width: 150,
    },
    {
      field: 'inCompanyName',
      headerName: '收货公司 ',
      width: 150,
    },
    {
      field: 'inWarehouseName',
      headerName: '收货仓库 ',
      width: 150,
    },
    {
      headerName: '仓库类别',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '出库数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '创建时间',
      field: 'createTime',
      width: 150,
    },
    {
      headerName: '状态',
      field: 'infoState',
      pinned: 'right',
      width: 150,
      cellRenderer: {
        template: `
            <a-button v-if="states == 2" status="success">已出库</a-button>
            <a-button v-else-if="states == 0" type="dashed" status="success">待审核</a-button>
            <a-button v-else-if="states == 3">已完结</a-button>
            <a-button v-else-if="states == 1">已驳回</a-button>
            `,
        setup(props: any) {
          return {
            states: props.params.data.infoState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '2'
            ? '已出库'
            : params.value == '3'
            ? '已完结'
            : params.value == '1'
            ? '已驳回'
            : params.value == '0'
            ? '待审核'
            : ''
        },
      },
    },
    {
      headerName: '操作',
      field: 'edit',
      pinned: 'right',
      filter: false,
      width: 150,
      cellRenderer: {
        template: `
          <el-button style="color:#165dff;" link @click="a" v-if="states==1">修改</el-button>
            `,
        setup(props: any) {
          const a = () => {
            redersOut2(props.params.data)
          }
          return {
            a,
            states: props.params.data.infoState,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
    },
  ]

  const tc2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '领料单号',
      field: 'materialRequestNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '公司',
      field: 'firm',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    // {
    //     headerName: '组名称',
    //     field: 'department',
    //     width: 150
    // },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '需求出库数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '需求时间',
      field: 'requisitionTime',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
  ]

  const tableColumns = [
    {
      title: '单号',
      key: 'orderNo',
      dataIndex: 'orderNo',
      width: 150,
    },
    {
      // 0手动创建出库 1针盘借出出库 2调拨出库
      title: '类型',
      key: 'infoType',
      dataIndex: 'infoType',
      slotName: 'infoType',
      width: 150,
    },
    {
      title: '出库类型',
      key: 'outStockType',
      dataIndex: 'outStockType',
      width: 150,
    },
    {
      title: '公司',
      key: 'companyName',
      dataIndex: 'companyName',
      width: 150,
    },
    {
      title: '仓库类别',
      key: 'warehouseTypeName',
      dataIndex: 'warehouseTypeName',
      width: 150,
    },
    {
      title: '仓库',
      key: 'warehouseName',
      dataIndex: 'warehouseName',
      width: 150,
    },
    {
      title: '机台号',
      key: 'machineCode',
      dataIndex: 'machineCode',
      width: 150,
    },
    {
      title: '机台名称',
      key: 'machineName',
      dataIndex: 'machineName',
      width: 150,
    },
    {
      title: '物料大类',
      key: 'majorCategory',
      dataIndex: 'majorCategory',
      width: 150,
    },
    {
      title: '物料中类',
      key: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
    },
    {
      title: '物料小类',
      key: 'subCategory',
      dataIndex: 'subCategory',
      width: 150,
    },
    {
      title: '物料编号',
      key: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
    },
    {
      title: '物料名称',
      key: 'materialName',
      dataIndex: 'materialName',
      width: 150,
    },
    {
      title: '规格',
      key: 'specification',
      dataIndex: 'specification',
      width: 150,
    },
    {
      title: '等级',
      key: 'grade',
      dataIndex: 'grade',
      width: 150,
    },
    {
      title: '原数量',
      key: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
    },
    {
      title: '已归还数量',
      key: 'returnNumed',
      dataIndex: 'returnNumed',
      width: 150,
    },
    {
      title: '待归还数量',
      key: 'awaitNumed',
      dataIndex: 'awaitNumed',
      slotName: 'awaitNumed',
      width: 150,
    },
    {
      title: '单位',
      key: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      title: '出库时间',
      key: 'createTime',
      dataIndex: 'createTime',
      width: 150,
    },
    {
      title: '归还时间',
      key: 'returnTime',
      dataIndex: 'returnTime',
      width: 150,
    },
    {
      title: '状态',
      key: 'infoState',
      dataIndex: 'infoState',
      slotName: 'infoState',
      fixed: 'right',
      width: 150,
    },
    {
      title: '操作',
      key: 'act',
      dataIndex: 'act',
      slotName: 'act',
      fixed: 'right',
      width: 150,
    },
  ]
  let tc3: any[] = tableColumns.map((o) => {
    let obj = {
      headerName: o.title,
      field: o.key,
      pinned: o['fixed'],
    }
    if (o.slotName === 'infoType') {
      obj['cellRenderer'] = {
        template: `<span>{{states==1?'针盘借出出库':states==2?'调拨出库':'手动创建出库'}}</span>`,
        setup(props: any) {
          return {
            states: props.params.data.infoType,
          }
        },
      }
      obj['cellStyle'] = (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      }
      obj['filterParams'] = {
        valueFormatter: function (params: any) {
          return params.value == '2'
            ? '调拨出库'
            : params.value == '1'
            ? '针盘借出出库'
            : '手动创建出库'
        },
      }
    }
    if (o.slotName === 'awaitNumed') {
      obj['cellRenderer'] = {
        template: `<div>{{val}}</div>`,
        setup(props: any) {
          let val = ref()
          val.value = props.params.data.totalNum - props.params.data.returnNumed
          return {
            val,
          }
        },
      }
    }
    if (o.slotName === 'infoState') {
      obj['cellRenderer'] = {
        template: `
      <a-button v-if="states == 2" status="success">已出库</a-button>
            <a-button v-else-if="states == 0" type="dashed" status="success">待审核</a-button>
            <a-button v-else-if="states == 3">已完结</a-button>
            <a-button v-else-if="states == 1">已驳回</a-button>
            `,
        setup(props: any) {
          return {
            states: props.params.data.infoState,
          }
        },
      }
      obj['cellStyle'] = (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      }
      obj['filterParams'] = {
        valueFormatter: function (params: any) {
          return params.value == '2'
            ? '已出库'
            : params.value == '3'
            ? '已完结'
            : params.value == '1'
            ? '已驳回'
            : params.value == '0'
            ? '待审核'
            : ''
        },
      }
    }
    if (o.slotName === 'act') {
      obj['filter'] = false
      obj['cellRenderer'] = {
        template: `<a-space><a-button @click="a" type="primary">归还</a-button>
      <a-button @click="b" type="primary">详情</a-button></a-space>`,
        setup(props: any) {
          const a = () => {
            handleReturn(props.params.data)
          }
          const b = () => {
            handleReturn1(props.params.data)
          }
          return {
            a,
            b,
          }
        },
      }
      obj['cellStyle'] = (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      }
    }
    return obj
  })

  let a = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 60,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 60,
      maxWidth: 60,
      lockPosition: 'left',
    },
  ]
  tc3 = a.concat(tc3)

  const tcA: any = [
    {
      headerName: '唯一编号',
      field: 'numberId',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '原数量',
      field: 'oldNum',
      width: 150,
    },
    {
      headerName: '已归还数量化',
      field: 'newNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
  ]

  let tabsKeys = ref(1)
  const selectHandler = () => {
    if (tabsKeys.value == 1) {
      cxYcList()
    } else if (tabsKeys.value == 2) {
      cxCgsList()
    } else if (tabsKeys.value == 3) {
      ghList()
    }
  }

  onMounted(() => {
    updateGridState01()
    updateGridState03()
    cxYcList()
  })

  const tabsChanges = (e: any) => {
    tabsKeys.value = e
    if (e == 1) {
      cxYcList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('zjcck.cx') ? '查询' : ''}`,
        '新增固资出库单',
        `${permissionStore.hasPermisson('zjcck.xzckd') ? '新建出库单' : ''}`,
        `${permissionStore.hasPermisson('zjcck.xzckd') ? '新建调拨单' : ''}`,
        `${permissionStore.hasPermisson('zjcck.xzbf') ? '新增报废' : ''}`,
        `${permissionStore.hasPermisson('zjcck.sh') ? '审核' : ''}`,
        `${permissionStore.hasPermisson('zjcck.sc') ? '删除' : ''}`,
      ]
    } else if (e == 2) {
      cxCgsList()
      toolbarList.value = ['查询', '出库']
    } else if (e == 3) {
      ghList()
      toolbarList.value = ['查询', '新建出库单', '新建调拨单', '批量归还']
      toolbarList.value = ['查询', '新建出库单', '新建调拨单']
    }
  }

  const cgDcuList = reactive({
    pwDds: '',
    pwDds2: '',
  })

  const cxCgsList = async () => {
    // isWlNameds,
    // isWlCodeds,
    post({
      url: 'wms/ironwareOutStock/getWjPendingInfo',
      data: {
        page: fySelet.page,
        size: fySelet.size,
        // firmName: pageData.c,
        // materialCode: pageData.d,
        // materialName: pageData.e,
      },
    }).then((res: any) => {
      gridOption2.value.setRowData(res.data.list)
      tableDataList2.value = res.data.list
      fySelet.total = res.data.total
    })
  }

  const cxYcList = () => {
    if (pageData.dropDownTime.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime[0]
      var endTime = pageData.dropDownTime[1]
    }
    post({
      url: 'wms/toolOutStock/getPage',
      data: {
        page: fySelet2.page,
        size: fySelet2.size,
        companyId: pageData.a == '' ? null : pageData.a,
        warehouseId: pageData.b,
        orderNo: pageData.g,
        // infoType: 1,
        materialCode: pageData.d,
        materialName: pageData.e,
        beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
        endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
      },
    }).then((res: any) => {
      gridOption.value.setRowData(res.data.data)
      setTableTotalRow(gridOption, res.data.data, ['totalNum'])
      tableDataList.value = res.data.data
      fySelet2.total = res.data.total
    })
  }

  const ghList = () => {
    if (pageData.dropDownTime.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime[0]
      var endTime = pageData.dropDownTime[1]
    }
    post({
      url: 'wms/toolOutStock/getPageBacklog',
      data: {
        page: fySelet3.page,
        size: fySelet3.size,
        companyId: pageData.a == '' ? null : pageData.a,
        warehouseId: pageData.b,
        orderNo: pageData.g,
        materialCode: pageData.d,
        materialName: pageData.e,
        infoType: 0,
        // infoState: 0,
        beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
        endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
      },
    }).then((res: any) => {
      gridOption3.value.setRowData(res.data.data)
      setTableTotalRow(gridOption3, res.data.data, ['totalNum', 'returnNumed', 'awaitNumed'])
      // tableDataList3.value = res.data.data
      fySelet3.total = res.data.total
    })
  }
  const cgRoutList: any = ref([])
  const redersOut = () => {
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请选择领料单号')
      return
    }
    for (let i = 0; i < gridOption2.value.getSelectedRows().length; i++) {
      for (let j = i + 1; j < gridOption2.value.getSelectedRows().length; j++) {
        if (
          gridOption2.value.getSelectedRows()[i].materialRequestNo !=
          gridOption2.value.getSelectedRows()[j].materialRequestNo
        ) {
          Message.error('请勾选相同领料单号')
          return
        }
      }
    }
    cgData.value = JSON.parse(JSON.stringify(gridOption2.value.getSelectedRows()))

    cgOut.visible = true
  }

  const cgOut = reactive({
    visible: false,
    title: '领料单出库',
    visible2: false,
  })

  const cgHandleOk = async () => {
    cgData.value.forEach((item: any) => {
      item['companyId'] = item.firmId
      item['companyName'] = item.firm
      item['infoType'] = 1
      item['outStockType'] = '领料出库'
      delete item.firmId
      delete item.firm
    })
    const { code, message } = await post({
      url: 'wms/ironwareOutStock/addOut',
      data: cgData.value,
    })
    if (code == 200) {
      cxYcList()
      cxCgsList()
      Message.success('成功')
      return true
    }
    Message.error(message)
    return false
  }

  const cgColumns: any = [
    {
      dataIndex: 'materialRequestNo',
      key: 'materialRequestNo',
      title: '领料单号',
      width: 150,
    },
    {
      dataIndex: 'firm',
      key: 'firm',
      title: '公司',
      width: 150,
    },
    {
      dataIndex: 'warehouseName',
      key: 'warehouseName',
      title: '仓库名称',
      width: 150,
    },
    {
      dataIndex: 'majorCategory',
      key: 'majorCategory',
      title: '物料大类',
      width: 150,
    },
    {
      title: '物料中类',
      key: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
    },
    {
      dataIndex: 'subCategory',
      key: 'subCategory',
      title: '物料小类',
      width: 150,
    },
    {
      dataIndex: 'materialCode',
      key: 'materialCode',
      title: '物料编号',
      width: 150,
    },
    {
      dataIndex: 'materialName',
      key: 'materialName',
      title: '物料名称',
      width: 150,
    },
    {
      dataIndex: 'totalNum',
      key: 'totalNum',
      title: '需求出库数量',
      width: 150,
    },
    {
      dataIndex: 'unit',
      key: 'unit',
      title: '单位 ',
      width: 150,
    },
    {
      dataIndex: 'requisitionTime',
      key: 'requisitionTime',
      title: '需求时间',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格 ',
      width: 150,
    },
  ]

  const warehouseChange = ($event: any, record: any) => {
    if ($event != '' || $event != undefined) {
      record['warehouseId'] = Number($event.split('-')[0])
      record['warehouseName'] = $event.split('-')[1]
      return
    }
  }

  const cadelvs = () => {
    cgData.value = []
    cgOut.visible = false
  }

  const delSles = () => {
    Modal.confirm({
      title: '系统提示',
      content: '确认删除选中的数据?',
      onOk: () => {
        post({
          url: 'wms/toolOutStock/delete',
          data: gridOption.value.getSelectedRows().map((res: any) => res.id),
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('删除成功')
            cxYcList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const audits = () => {
    Modal.confirm({
      title: '系统提示',
      content: '确认是否审核选中的数据?',
      onOk: () => {
        post({
          url: 'wms/toolOutStock/audit',
          data: {
            infoState: 2,
            infos: gridOption.value.getSelectedRows().map((res: any) => {
              return { id: res.id }
            }),
          },
        }).then((res: any) => {
          if (res.code == 200) {
            Message.success('成功')
            cxYcList()
          } else Message.error(res.message)
        })
      },
    })
  }

  const cgData: any = ref([])

  const adddbs = (num: any) => {
    if (num == 1) {
      dbPageDate.titles = '新建出库单'
    } else if (num == 2) {
      dbPageDate.titles = '新建调拨单'
    } else if (num == 3) {
      dbPageDate.titles = '新增固资出库单'
      searchData.outStockType = '固资出库'
    } else if (num == 4) {
      dbPageDate.titles = '新增报废'
      searchData.outStockType = '报废出库'
    }
    dbPageDate.showAdd = true
  }

  const dbPageDate = reactive({
    showAdd: false,
    titles: '新建出库单',
    showAdd5: false,
  })

  const formRef = ref()

  const sideOk = async () => {
    if (wlListArray.value.length == 0) {
      Message.warning({
        content: '请新增至少一条物料信息',
        duration: 5000,
      })
      return
    }
    if (dbPageDate.titles == '新增固资出库单') {
      formRef.value?.validate().then((err: any) => {
        if (!err) {
          let ob = {}
          ob['infoList'] = wlListArray.value
          ob['machineName'] = searchData.machineName
          ob['machineCode'] = searchData.machineCode
          ob['outStockType'] = searchData.outStockType
          ob['outStockTypeId'] = 0
          ob['firmId'] = searchData.fhFirmId
          ob['firmName'] = searchData.fhFirm
          post({
            url: 'wms/toolOutStock/addGuZiOutStock',
            data: ob,
          }).then(({ code, message }) => {
            if (code == 200) {
              cxYcList()
              Message.success('成功')
              for (let i in searchData) {
                searchData[i] = null
              }
              wlListArray.value = []
              dbPageDate.showAdd = false
            } else {
              Message.error(message)
            }
          })
        }
      })
    } else {
      for (let i = 0; i < wlListArray.value.length; i++) {
        if (wlListArray.value[i].totalNum == 0) {
          Message.error('数量必须大于0')
          return
        }
        if (
          wlListArray.value[i].grade == '' ||
          wlListArray.value[i].grade == null ||
          wlListArray.value[i].grade == undefined
        ) {
          Message.error('等级必填')
          return
        }
      }
      formRef.value?.validate().then((err: any) => {
        if (!err) {
          if (dbPageDate.titles == '新建出库单') {
            let ob = {}
            ob['addInfo'] = wlListArray.value
            ob['warehouseId'] = Number(searchData.fhWh.split('-')[0])
            ob['machineName'] = searchData.machineName
            ob['machineCode'] = searchData.machineCode
            ob['outStockType'] = searchData.outStockType
            ob['infoType'] = 0
            ob['warehouseName'] = searchData.fhWh.split('-')[1]
            ob['companyId'] = searchData.fhFirmId
            ob['companyName'] = searchData.fhFirm
            // wlListArray.value.forEach((item: any) => {
            //     item['companyId'] = searchData.fhFirmId
            //     item['companyName'] = searchData.fhFirm
            //     item['inCompanyId'] = searchData.shFirmId
            //     item['inCompanyName'] = searchData.shFirm
            //     item['inWarehouseTypeName'] = searchData.shWhType
            //     item['warehouseId'] = Number(searchData.fhWh.split('-')[0])
            //     item['warehouseName'] = searchData.fhWh.split('-')[1]
            //     item['inWarehouseId'] = Number(searchData.shWh.split('-')[0])
            //     item['inWarehouseName'] = searchData.shWh.split('-')[1]
            //     item['infoType'] = 2
            //     item['outStockType'] = '调拨单出库'
            //     item['warehouseTypeName'] = '五金仓'
            // })
            post({
              url: 'wms/toolOutStock/addOutStock',
              data: ob,
            }).then(({ code, message }) => {
              if (code == 200) {
                cxYcList()
                Message.success('成功')
                for (let i in searchData) {
                  searchData[i] = null
                }
                wlListArray.value = []
                dbPageDate.showAdd = false
              } else {
                Message.error(message)
              }
            })
          } else if (dbPageDate.titles == '新增报废') {
            let ob = {}
            ob['addInfo'] = wlListArray.value
            ob['warehouseId'] = Number(searchData.fhWh.split('-')[0])
            ob['machineName'] = searchData.machineName
            ob['machineCode'] = searchData.machineCode
            ob['outStockType'] = searchData.outStockType
            ob['infoType'] = 0
            ob['warehouseName'] = searchData.fhWh.split('-')[1]
            ob['companyId'] = searchData.fhFirmId
            ob['companyName'] = searchData.fhFirm
            post({
              url: 'wms/toolOutStock/addOutStock',
              data: ob,
            }).then(({ code, message }) => {
              if (code == 200) {
                cxYcList()
                Message.success('成功')
                for (let i in searchData) {
                  searchData[i] = null
                }
                wlListArray.value = []
                dbPageDate.showAdd = false
              } else {
                Message.error(message)
              }
            })
          } else if (dbPageDate.titles == '新建调拨单') {
            wlListArray.value.forEach((item: any) => {
              item['companyId'] = searchData.fhFirmId
              item['companyName'] = searchData.fhFirm
              item['inCompanyId'] = searchData.shFirmId
              item['inCompanyName'] = searchData.shFirm
              item['inWarehouseTypeName'] = searchData.shWhType
              item['warehouseId'] = Number(searchData.fhWh.split('-')[0])
              item['warehouseName'] = searchData.fhWh.split('-')[1]
              item['inWarehouseId'] = Number(searchData.shWh.split('-')[0])
              item['inWarehouseName'] = searchData.shWh.split('-')[1]
              item['infoType'] = 2
              item['outStockType'] = '调拨单出库'
              item['warehouseTypeName'] = '制具仓'
              delete item.id
            })
            post({
              url: 'wms/toolOutStock/addOutStock',
              data: {
                addInfo: wlListArray.value,
                warehouseId: Number(searchData.fhWh.split('-')[0]),
                companyId: searchData.fhFirmId,
                outStockType: '调拨单出库',
                warehouseName: searchData.fhWh.split('-')[1],
                infoType: 2,
                companyName: searchData.fhFirm,
              },
            }).then(({ code, message }) => {
              if (code == 200) {
                cxYcList()
                Message.success('成功')
                for (let i in searchData) {
                  searchData[i] = null
                }
                wlListArray.value = []
                dbPageDate.showAdd = false
              } else {
                Message.error(message)
              }
            })
          }
        }
      })
    }
  }

  const sideNo = () => {
    for (let i in searchData) {
      searchData[i] = ''
    }
    wlListArray.value = []
    dbPageDate.showAdd = false
  }

  const searchData: any = reactive({
    fhFirm: '',
    fhFirmId: null,
    fhWh: '',
    shFirm: '',
    shFirmId: null,
    shWhType: '',
    shWh: '',
    outStockType: '',
    materialCode: '',
    materialName: '',
  })

  const configCascader = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const configCascader2 = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '收货公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService = new WHService()
  const fhWhList: any = whService.whList
  const changeCascader = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchData.fhWh = ''
    searchData.fhFirmId = corporateId
    searchData.fhFirm = corporateLabel
    whService.getWarhouseListByFirmId(corporateId, '制具仓')
  }
  const changeCascader2 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchData.shWh = ''
    searchData.shFirmId = corporateId
    searchData.shFirm = corporateLabel
    whService.getWarhouseListByFirmId(corporateId, '制具仓')
  }
  const whTypeList: any = ref([])

  const whService2 = new WHService()
  const shWhList: any = whService2.whList
  const whTypeChanges = (e: any) => {
    whService2.getWarhouseListByFirmId(searchData.shFirmId, e)
  }

  const wlListArray: any = ref([])

  const tableColumnsWl: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      field: 'grade',
      headerName: '等级',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      field: 'specification',
      headerName: '规格 ',
      width: 150,
    },
    {
      headerName: '数量',
      field: 'totalNum',
      width: 150,
      cellRenderer: {
        template: `
      <a-input-number v-model="res.totalNum" class="input-demo bacClass" :min="0"
                  :max="res.totalNum2 - res.useNum" :precision="2" />
            `,
        setup(props: any) {
          const res = ref(props.params.data)
          res.value.totalNum = res.value.totalNum2 - res.value.useNum
          return {
            res,
          }
        },
      },
    },
    {
      field: 'totalNum2',
      headerName: '库存数量',
      width: 150,
    },
    {
      field: 'useNum',
      headerName: '针盘已使用数量',
      width: 150,
    },
  ]
  let typeIds = 0
  const addLine = () => {
    if (dbPageDate.titles == '新增固资出库单') {
      if (searchData.fhFirm == '') {
        Message.error('请先选择发货公司')
        return
      }
      isLyCodeds.value = ''
      isLyNameds.value = ''
      wlListXqs1.value = []
      selectedRowKeys5.value = []
      visibleYl1.value = true
    } else {
      if (searchData.fhWh == '' || searchData.fhFirm == '') {
        Message.error('请先选择发货公司仓库')
        return
      }
      isLyCodeds.value = ''
      isLyNameds.value = ''
      wlListXqs.value = []
      selectedRowKeys2.value = []
      visibleYl.value = true
      // wlListArray.value.push({
      //     typeIds: typeIds++,
      //     majorCategory: '',
      //     subCategory: '',
      //     materialCode: '',
      //     unit: '',
      //     materialName: '',
      //     totalNum: 0
      // })
    }
  }

  const selectedRowKeysWl: any = ref([])

  const delLine = () => {
    // if (selectedRowKeysWl.value.length === 0) {
    //   Message.error({
    //     content: '请先勾选',
    //     duration: 5000,
    //   })
    //   return
    // }
    const selectedData = gridOption6.value.getSelectedRows()
    if (selectedData.length == 0) {
      Message.error({
        content: '请先勾选',
        duration: 5000,
      })
      return
    }
    // if (dbPageDate.titles == '新增固资出库单') {
    // wlListArray.value = wlListArray.value.filter(function (o: any) {
    //   return selectedRowKeysWl.value.indexOf(o['numberId']) === -1
    // })
    ElMessageBox.confirm('确认删除选中单据?', '提示', {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    })
      .then(() => {
        gridOption6.value.applyTransaction({ remove: gridOption6.value.getSelectedRows() })
        Message.success({
          content: '删除成功',
          duration: 5000,
        })
      })
      .catch(() => {})
    // } else {
    //   wlListArray.value = wlListArray.value.filter(function (o: any) {
    //     return selectedRowKeysWl.value.indexOf(o['typeLesIds']) === -1
    //   })
    // }
  }

  const wlPageDatas: any = reactive({
    wlListL: [],
    wlListS: [],
    wlList: [],
  })

  const focusSel = () => {
    post({
      url: 'purchase/MaterialBigClass/getFieldValue',
      data: { bigClassName: '', deleteState: 0 },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlListL = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const focusSel1 = (e: any) => {
    if (e.majorCategory == '') {
      Message.error('请先选择物料大类')
      return
    }
    post({
      url: 'purchase/MaterialSubClass/getFieldValue',
      data: { bigClassName: e.majorCategory },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlListS = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const focusSel2 = (val: any) => {
    post({
      url: 'purchase/MaterialInfo/getFieldValueWms',
      data: val,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }

  const cxKcsl = async (val: any, val2: any) => {
    const res = await post({
      url: 'wms/toolStockSummary/getToolsStockNum',
      data: {
        materialCode: val,
        grade: val2,
        warehouseId: Number(searchData.fhWh.split('-')[0]),
      },
    })
    if (res.code == 200) {
      return res.data.totalNum
    }
  }

  const changeWl = (record: any, val: any) => {
    if (val == '') {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      return
    }
    let list2 = wlListArray.value.filter(function (o: any) {
      return o['materialName'] == record['materialName']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialName'] == val
    })
    if (list.length > 0) {
      record['materialCode'] = list[0]['materialCode']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
      record['majorCategory'] = list[0]['materialL']
      record['subCategory'] = list[0]['materialS']
      cxKcsl(record['materialCode'], record['grade']).then((res: any) => {
        record['totalNum2'] = res
      })
    }
  }
  const changeWl2 = (record: any, val: any) => {
    if (val == '') {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      return
    }
    let list2 = wlListArray.value.filter(function (o: any) {
      return o['materialCode'] == record['materialCode']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['unit'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialCode'] == val
    })
    if (list.length > 0) {
      record['materialName'] = list[0]['materialName']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
      record['majorCategory'] = list[0]['materialL']
      record['subCategory'] = list[0]['materialS']
      cxKcsl(val, record['grade']).then((res: any) => {
        record['totalNum2'] = res
      })
    }
  }
  const qkChanges = (record: any) => {
    record['materialCode'] = ''
    record['unit'] = ''
    record['materialName'] = ''
  }

  const gradrList: any = ref([])

  const gradeChange = (e: any) => {
    if (e.materialName == '' || e.materialCode == '') {
      Message.error('请先选择物料')
      return
    }
    post({
      url: 'dict/dictTypeDetail/getListByMap',
      data: {
        codeType: 36,
        detailName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList.value = data
      }
    })
  }

  const totalNum2: any = ref()

  const grachanges = (e: any) => {
    cxKcsl(e['materialCode'], e['grade']).then((res: any) => {
      e['totalNum2'] = res
    })
  }

  const configCascader3 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService3 = new WHService()
  const fhWhList3: any = whService3.whList
  const changeCascader3 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.b = ''
    pageData.a = corporateId
    whService3.getWarhouseListByFirmId(corporateId, '制具仓')
  }
  let CkList = ref([])
  let outStockTypeList = ref([])
  //查询出库类型
  function cxOutStockType() {
    if (dbPageDate.titles == '新增固资出库单') {
      post({
        url: 'wms/stockoutType/getStockoutTypePara2',
        data: {
          firmId: searchData.fhFirmId,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          outStockTypeList.value = res.data
        }
      })
    } else {
      post({
        url: 'wms/stockoutType/getStockoutTypePara',
        data: {
          warehouseId: Number(searchData.fhWh.split('-')[0]),
        },
      }).then((res: any) => {
        if (res.code == 200) {
          outStockTypeList.value = res.data
        }
      })
    }
  }
  const machineNameCode: any = ref([])

  const machineNameCodeCx = (val?: string) => {
    post({
      url: 'planSingle/machine/getFieldValueWms',
      data: {
        machineCode: val ? val : '',
        companyId: searchData.fhFirmId,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        machineNameCode.value = data
      }
    })
  }

  const machineNameCodeChange = (e: any) => {
    searchData.machineCode = e.split('-')[0]
    // searchData.machineName = e.split('-')[1]
    const namePattern = /-(.*)$/ // 正则表达式匹配机台名称部分
    const nameMatch = e.match(namePattern)
    if (nameMatch && nameMatch.length > 1) {
      searchData.machineName = nameMatch[1]
    } else {
      searchData.machineName = ''
    }
  }

  const visibleYl = ref(false)
  const visibleYl1 = ref(false)
  const isLyCodeds: any = ref('')
  const isLyNameds: any = ref('')
  const selectedRowKeys2: any = ref([])
  const selectedRowKeys3: any = ref([])
  const selectedRowKeys5: any = ref([])
  const wlListXqs: any = ref([])
  const wlListXqs1: any = ref([])
  const isLists: any = reactive<{
    majorCategory: ''
    middleCategory: ''
    subCategory: ''
    materialName: ''
    specification: ''
  }>
  const handleOks = () => {
    if (gridOption4.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    }
    // //判断是否有相同的物料编号和等级
    // if (wlListXqs.value.length > 0 && wlListArray.value.length > 0) {
    //   for (let i = 0; i < wlListArray.value.length; i++) {
    //     for (let j = 0; j < wlListXqs.value.length; j++) {
    //       if ((wlListArray.value[i]['materialCode'] == wlListXqs.value[j]['materialCode']) && (wlListArray.value[i]['grade'] == wlListXqs.value[j]['grade'])) {
    //         Message.error('请勿勾选相同等级的物料')
    //         return
    //       }
    //     }
    //   }
    // }
    // let islistArray: any = []
    // for (let i = 0; i < wlListXqs.value.length; i++) {
    //   if (selectedRowKeys2.value.includes(wlListXqs.value[i].typeLesIds)) {
    //     islistArray.push(wlListXqs.value[i])
    //   }
    // }
    // if (wlListArray.value.length != 0) {
    //   let wlAarray: any = []
    //   for (let i = 0; i < islistArray.length; i++) {
    //     wlAarray.push(islistArray[i].materialCode)
    //   }
    //   for (let i = 0; i < wlListArray.value.length; i++) {
    //     if (wlAarray.includes(wlListArray.value[i].materialCode)) {
    //       Message.error('请勿勾选相同物料')
    //       return false
    //     }
    //   }
    // }
    // islistArray.forEach((res: any) => {
    //   res['totalNum'] = 0
    // })
    let arr3 = gridOption4.value.getSelectedRows()
    let arr = wlListArray.value
    for (const item of arr) {
      const found = arr3.find((elem: any) => elem.materialCode === item.materialCode)
      if (!found) {
        arr3.push(item)
      }
    }
    arr3.forEach((item: any) => {
      // item.totalNum = item.availableNum - item.useNum;
      item.totalNum2 = item.totalNum
    })
    wlListArray.value = arr3
    // wlListArray.value.push(...islistArray)
    visibleYl.value = false
    return true
  }
  const handleOks5 = () => {
    // let islistArray: any = []
    // for (let i = 0; i < wlListXqs1.value.length; i++) {
    //   if (selectedRowKeys5.value.includes(wlListXqs1.value[i].numberId)) {
    //     islistArray.push(wlListXqs1.value[i])
    //   }
    // }
    if (gridOption5.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    }
    let arr3 = gridOption5.value.getSelectedRows()
    let arr = wlListArray.value
    for (const item of arr) {
      const found = arr3.find((elem: any) => elem.numberId === item.numberId)
      if (!found) {
        arr3.push(item)
      }
    }
    arr3.forEach((item: any) => {
      // item.totalNum = item.availableNum - item.useNum;
      item.totalNum2 = item.totalNum
    })
    wlListArray.value = arr3
    visibleYl1.value = false
    return true
  }

  const handleCancels = () => {
    visibleYl.value = false
  }
  const handleCancels5 = () => {
    visibleYl1.value = false
  }

  const cgColumns5: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'companyName',
      width: 150,
    },
    {
      field: 'warehouseTypeName',
      headerName: '仓库类型名称',
      width: 150,
    },
    {
      field: 'warehouseName',
      headerName: '仓库名称',
      width: 150,
    },
    {
      field: 'majorCategory',
      headerName: '物料大类',
      width: 150,
    },
    {
      field: 'middleCategory',
      headerName: '物料中类',
      width: 150,
    },
    {
      field: 'subCategory',
      headerName: '物料小类',
      width: 150,
    },
    {
      field: 'materialCode',
      headerName: '物料编号',
      width: 150,
    },
    {
      field: 'materialName',
      headerName: '物料名称',
      width: 150,
    },
    {
      field: 'grade',
      headerName: '等级',
      width: 150,
    },
    {
      field: 'totalNum',
      headerName: '数量 ',
      width: 150,
    },
    {
      field: 'useNum',
      headerName: '针盘使用数量 ',
      width: 150,
    },
    {
      field: 'unit',
      headerName: '单位',
      width: 150,
    },
  ]

  const fySelet4: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })
  const fySelet5: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })
  const PageSize4 = (val: any) => {
    fySelet4.page = val
    cxCgsLists()
  }

  const change4 = (val: any) => {
    fySelet4.size = val
    cxCgsLists()
  }
  const PageSize5 = (val: any) => {
    fySelet5.page = val
    cxCgsLists1()
  }

  const change5 = (val: any) => {
    fySelet5.size = val
    cxCgsLists1()
  }
  const cxCgsLists = async () => {
    const res: any = await post({
      url: 'wms/toolStockSummary/getPage',
      data: {
        page: fySelet4.page,
        size: fySelet4.size,
        warehouseId: Number(searchData.fhWh.split('-')[0]),
        materialCode: isLyCodeds.value,
        materialName: isLyNameds.value,
      },
    })
    if (res.code == 200) {
      wlListXqs.value = res.data.data
      gridOption4.value.setRowData(res.data.list)
      wlListXqs.value.forEach((res: any) => {
        delete res.id
        res['typeLesIds'] = typeIds++
        res['totalNum2'] = res.totalNum
      })
      fySelet4.total = res.data.total
    }
  }
  const cxCgsLists1 = async () => {
    const res: any = await post({
      url: 'wms/ironwareStockInfo/getPage',
      data: {
        page: fySelet5.page,
        size: fySelet5.size,
        ...isLists,
        stockState: 1,
        fixedShiftState: 0,
        fixedAssetsBorrowState: 0,
        fixedScrapState: 0,
        toolStockState: 0,
        companyId: searchData.fhFirmId,
      },
    })
    if (res.code == 200) {
      gridOption5.value.setRowData(res.data.list)
      wlListXqs1.value = res.data.list
      wlListXqs1.value.forEach((res: any) => {
        delete res.id
      })
      fySelet5.total = res.data.total
      // wlListXqs1.value = res.data.list
      // fySelet5.total = res.data.total
      // wlListXqs1.value.forEach((res: any) => {
      //   delete res.id
      // })
      // // let ob = []
      // if (wlListArray.value.length != 0) {
      //   selectedRowKeys5.value = wlListArray.value.map((item: any) => { return item.numberId })
      // }
    }
  }
  const redersOut2 = (data: any) => {
    cgData2.value = JSON.parse(JSON.stringify([data]))
    cgOut.visible2 = true
  }
  const cgHandleOk2 = async () => {
    const { code, message } = await post({
      url: 'wms/toolOutStock/updateById',
      data: cgData2.value[0],
    })
    if (code == 200) {
      cxYcList()
      cxCgsList()
      Message.success('成功')
      return true
    }
    Message.error(message)
    return false
  }
  const cadelvs2 = () => {
    cgData2.value = []
    cgOut.visible2 = false
  }
  const cgData2: any = ref([])

  const cgColumns2: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      field: 'orderNo',
      headerName: '单号',
      width: 150,
    },
    {
      field: 'outStockType',
      headerName: '出库类型',
      width: 150,
    },
    {
      field: 'companyName',
      headerName: '公司',
      width: 150,
    },
    {
      field: 'warehouseTypeName',
      headerName: '仓库类别',
      width: 150,
    },
    {
      field: 'warehouseName',
      headerName: '仓库',
      width: 150,
    },

    {
      field: 'inWarehouseTypeName',
      headerName: '收货仓库类型',
      width: 150,
    },
    {
      field: 'inCompanyName',
      headerName: '收货公司 ',
      width: 150,
    },
    {
      field: 'inWarehouseName',
      headerName: '收货仓库 ',
      width: 150,
    },
    {
      field: 'majorCategory',
      headerName: '物料大类',
      width: 150,
    },
    {
      field: 'middleCategory',
      headerName: '物料中类',
      width: 150,
    },
    {
      field: 'subCategory',
      headerName: '物料小类',
      width: 150,
    },
    {
      field: 'materialCode',
      headerName: '物料编号',
      width: 150,
    },
    {
      field: 'materialName',
      headerName: '物料名称',
      width: 150,
    },
    {
      field: 'specification',
      headerName: '规格',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      field: 'price',
      headerName: '单价',
      width: 150,
    },
    {
      field: 'unit',
      headerName: '单位',
      width: 150,
    },
    {
      field: 'totalNum',
      headerName: '出库数量',
      width: 150,
      fixed: 'right',
      cellRenderer: {
        template: `
      <a-input-number class="bacClass" v-model="res.totalNum" :max="res.totalNum2 - res.useNum"
            :min="0" :precision="2" > </a-input-number>
            `,
        setup(props: any) {
          const res = ref(props.params.data)
          return {
            res,
          }
        },
      },
    },
  ]

  const compareDate = (dateTime1: any, dateTime2: any) => {
    var formatDate1 = new Date(dateTime1)
    var formatDate2 = new Date(dateTime2)
    if (formatDate1 > formatDate2) {
      return true
    } else {
      return false
    }
  }
  const onSelect = (dateString: any, date: any) => {
    pageData.dropDownTime = {
      beginTime: dateString[0],
      endTime: dateString[1],
    }
  }
  const onClear = () => {
    pageData.dropDownTime = []
  }

  const oneList = ref(false)
  const moreList = ref(false)
  const visible3 = ref(false)
  const visibleA = ref(false)
  const visible4 = ref(false)
  const selectedRowKeys1 = ref([])
  const dataForm3: any = reactive({
    infoType: null,
    totalNumIng: null,
    degraded: '',
    degraNum: null,
    scrapNum: null,
    Loading: false,
  })
  //归还类型下拉框
  let outStockTypeList2 = ref([])
  function cxOutStockType2(record: any) {
    post({
      url: 'wms/stockinType/getStockinTypePara',
      data: {
        warehouseId: gridOption3.value.getSelectedRows()[0].warehouseId,
      },
    }).then((res: any) => {
      if (res.code == 200) {
        outStockTypeList2.value = res.data
      }
    })
  }
  let outStockTypeList3 = ref([])
  function cxOutStockType3(record: any) {
    let list = []
    for (let i = 0; i < tableDataList4.value.length; i++) {
      var ob = {}
      ob['warehouseId'] = tableDataList4.value[i].warehouseId
      post({
        url: 'wms/stockinType/getStockinTypePara',
        data: {
          warehouseId: ob['warehouseId'],
        },
      }).then((res: any) => {
        if (res.code == 200) {
          outStockTypeList3.value = res.data
        }
      })
    }
  }

  //降后等级下拉框
  const gradrList2: any = ref([])
  const gradeChange2 = () => {
    dataForm3.degraNum === null
    post({
      url: 'dict/dictTypeDetail/getListByMapGrade',
      data: {
        codeType: 36,
        detailName: gridOption3.value.getSelectedRows()[0].grade,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList2.value = data
      }
    })
  }
  const gradrList3: any = ref([])
  const gradeChange3 = (record: any) => {
    record.degraNum === null
    post({
      url: 'dict/dictTypeDetail/getListByMapGrade',
      data: {
        detailName: record.grade,
        codeType: 36,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList3.value = data
      }
    })
  }

  const degraNum = () => {
    if (dataForm3.degraded === '') {
      Message.warning('请先选择降后等级!')
      return false
    }
  }

  const degraNum1 = (record: any) => {
    if (record.degraded === '' || record.degraded === null || record.degraded === undefined) {
      Message.warning('请先选择降后等级!')
      return false
    }
  }

  const Num = (num: number, res: any) => {
    // // 归还数量+降等数量+报废数量
    // let num1 = dataForm3.totalNumIng + dataForm3.degraNum + dataForm3.scrapNum
    // // 待归还数量
    // let num2 = gridOption3.value.getSelectedRows()[0].totalNum - gridOption3.value.getSelectedRows()[0].returnNumed
    // if (num1 > num2) {
    //   Message.error('数量超过!')
    //   return false
    // }
    if (num == 1) {
      let ob = res.oldNum - res.newNum
      if (res.newNum2 > ob) {
        nextTick(() => {
          Message.error('数量超过,请重新填写!')
          res.newNum2 = 0
        })
      }
    } else if (num == 2) {
      if (res.degraNum > res.newNum2) {
        nextTick(() => {
          Message.error('降等数量不能超过归还数量!')
          res.degraNum = 0
        })
      }
    }
  }

  const Num1 = () => {
    for (let i = 0; i < tableDataList4.value.length; i++) {
      // 归还数量+降等数量+报废数量
      let num1 =
        tableDataList4.value[i].totalNumIng +
        tableDataList4.value[i].degraNum +
        tableDataList4.value[i].scrapNum
      // 待归还数量
      let num2 = tableDataList4.value[i].totalNum - tableDataList4.value[i].returnNumed
      if (num1 > num2) {
        Message.error('数量超过!')
        return false
      }
    }
  }
  const confirmDataParams = ref()
  const handleReturn = (record: any) => {
    post({
      url: 'wms/toolOutStock/selectRecDetail',
      data: {
        orderNo: record.orderNo,
        materialCode: record.materialCode,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        data.forEach((item: any) => {
          ;(item.newNum2 = item.oldNum - item.newNum),
            (item.degraded = 'A'),
            (item.degraNum = 0),
            (item.scrapNum = 0)
        })
        confirmDataParams.value = data
        gridOptionRef2.value.setdataListIterface(data)
      }
    })
    oneList.value = true
    visible3.value = true
    dataForm3.Loading = false
  }
  // 详情
  const handleReturn1 = (record: any) => {
    post({
      url: 'wms/toolOutStock/selectRecDetail',
      data: {
        orderNo: record.orderNo,
        materialCode: record.materialCode,
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        tableDataListA.value = data
        visibleA.value = true
      }
    })
  }
  const confirmDataParams2: any = ref()
  const returnList = () => {
    if (gridOption3.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据!')
      return false
    }
    //限制同一单号可批量归还
    let selectData = gridOption3.value.getSelectedRows()
    if (!selectData.every((item: any) => item.orderNo === selectData[0].orderNo)) {
      Message.error('请勾选相同的单号!')
      return false
    }
    // tableDataList4.value = gridOption3.value.getSelectedRows()
    selectData.filter((o: any) => {
      o['totalNumIng'] = 0.0
      o['degraNum'] = 0.0
      o['scrapNum'] = 0.0
      o['inStockType'] = ''
      o['degraded'] = ''
    })
    confirmDataParams2.value = selectData
    gridOptionRef3.value.setdataListIterface(selectData)
    moreList.value = true
    visible4.value = true
    dataForm3.Loading = false
  }

  const handleOk = () => {
    // if (!dataForm3.totalNumIng && !dataForm3.degraNum && !dataForm3.scrapNum) {
    //   Message.warning('请填写数量!')
    //   return false
    // }
    // if (dataForm3.totalNumIng + dataForm3.degraNum + dataForm3.scrapNum <= 0) {
    //   Message.warning('归还数量不能小于等于0!')
    //   return false
    // }
    // if (!dataForm3.inStockType) {
    //   Message.warning('请选择归还类型!')
    //   return false
    // }
    // let list = []
    // for (let i = 0; i < tableDataList4.value.length; i++) {
    //   var ob = {}
    //   for (let key in tableDataList4.value[i]) {
    //     ob[key] = tableDataList4.value[i][key]
    //   }
    //   ob['awaitNumed'] = tableDataList4.value[i].totalNum - tableDataList4.value[i].returnNumed,
    //     ob['inStockType'] = dataForm3.inStockType,
    //     ob['totalNumIng'] = dataForm3.totalNumIng,
    //     ob['degraded'] = dataForm3.degraded,
    //     ob['degraNum'] = dataForm3.degraNum,
    //     ob['scrapNum'] = dataForm3.scrapNum
    //   list.push(ob)
    // }
    post({
      url: 'wms/toolOutStock/saveReturn',
      data: confirmDataParams.value,
    }).then(({ code, data, message }: any) => {
      if (code == 200) {
        visible3.value = false
        dataForm3.Loading = false
        ghList()
      } else {
        Message.error(message)
        return false
      }
    })
  }

  const handleOk1 = async () => {
    for (let i = 0; i < confirmDataParams2.value.length; i++) {
      let o: any = confirmDataParams2.value[i]
      if (o['totalNumIng'] == null && o['degraNum'] == null && o['scrapNum'] == null) {
        Message.warning('请填写数量!')
        return false
      }
      if (o['totalNumIng'] + o['degraNum'] + o['scrapNum'] <= 0) {
        Message.warning('归还数量不能小于等于0!')
        return false
      }
      if (o['inStockType'] == null) {
        Message.warning('请选择归还类型!')
        return false
      }
    }
    let list = []
    for (let i = 0; i < confirmDataParams2.value.length; i++) {
      var ob = {}
      for (let key in confirmDataParams2.value[i]) {
        ob[key] = confirmDataParams2.value[i][key]
      }
      ;(ob['awaitNumed'] =
        confirmDataParams2.value[i].totalNum - confirmDataParams2.value[i].returnNumed),
        list.push(ob)
    }
    try {
      const res = await post({
        url: 'wms/toolInStock/outOrderReturnInStock',
        data: list,
      })
      if (res.code == 200) {
        visible4.value = false
        dataForm3.Loading = false
        ghList()
      } else {
        Message.error(res.message)
        return false
      }
    } catch (error) {
      console.log(error)
    } finally {
      dataForm3.Loading = false
    }
  }

  //删除
  const delRow = (record: any) => {
    if (tableDataList4.value.length === 1) {
      Message.error('单据中至少保留一条物料信息!')
      return false
    }
    tableDataList4.value = tableDataList4.value.filter(function (o: any) {
      return o['materialCode'] !== record['materialCode']
    })
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('OrderDeliveryList4-1', gridOption, colState, tc)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState03, updateGridState: updateGridState03 } =
    saveOrUpdateGridState03('OrderDeliveryList4-3', gridOption3, colState3, tc3)
  const onColumnMoved3 = () => {
    saveGridState03()
  }
  const onColumnResized3 = () => {
    saveGridState03()
  }
  const onColumnVisible3 = () => {
    saveGridState03()
  }

  const gridOption5_1 = ref()
  const gridReady5_1 = (params: any) => {
    gridOption5_1.value = params.api
  }
  const tableDataList5_1 = ref([])

  const dc5: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '唯一编码',
      field: 'numberId',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格 ',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
  ]
  const xzgzckds = () => {
    dbPageDate.showAdd5 = true
  }
</script>

<style scoped lang="less">
  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }

  :deep(.arco-table-td-content) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  .cgisDatas {
    margin-bottom: 15px;
    width: 50%;
    display: flex;
    justify-content: space-between;
  }

  :deep(.arco-picker input) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker-separator) {
    padding: 0 !important;
  }
</style>
<style>
  .arco-drawer-body {
    overflow: hidden;
  }
  .arco-modal-body {
    height: 100%;
  }
  .el-scrollbar__view {
    height: 100%;
  }
</style>
